package com.maxvision.mybatis.config;

import cn.hutool.core.date.DateTime;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

/**
 * mybatis-plus 自动填充创建时间和修改时间
 *
 * @author HuangRongFu
 * @date 2022/10/17
 */

@Component
public class MybatisFillConfig implements MetaObjectHandler{
    
    @Override
    public void insertFill(MetaObject metaObject) {
        
        this.setFieldValByName("createTime", new DateTime(), metaObject);
        this.setFieldValByName("updateTime", new DateTime(), metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {

        this.setFieldValByName("updateTime", new DateTime(), metaObject);
    }
}
